package cn.tedu.system.oa.dept.controller;

import cn.tedu.system.oa.base.response.JsonResult;
import cn.tedu.system.oa.dept.pojo.dto.DeptQuery;
import cn.tedu.system.oa.dept.pojo.entity.Dept;
import cn.tedu.system.oa.dept.pojo.param.DeptSaveParam;
import cn.tedu.system.oa.dept.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/oa/dept/")
@Slf4j
@Api(tags = "02.部门模块")
public class DeptController {
    @Autowired
    DeptService deptService;

    @ApiOperation("查询部门")
    @GetMapping("select")
    public JsonResult selectDept(DeptQuery deptQuery){
        log.debug("查询部门,参数={}",deptQuery);
        List<Dept> list = deptService.selectDept(deptQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("新增/修改部门")
    @PostMapping("save")
    public JsonResult saveDept(DeptSaveParam deptSaveParam){
        log.debug("保存部门数据,参数={}",deptSaveParam);
        deptService.saveDept(deptSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除部门")
    @PostMapping("delete/{deptId}")
    public JsonResult deleteDept(@PathVariable Integer deptId){
        log.debug("删除部门,参数={}",deptId);
        deptService.deleteDept(deptId);
        return JsonResult.ok();
    }
}
